package com.woniuxy.venueweb.controller;


import cn.hutool.core.bean.BeanUtil;
import com.woniuxy.core.model.Result;
import com.woniuxy.core.util.MyJwtUtil;
import com.woniuxy.core.util.PageInfo;
import com.woniuxy.venuedao.model.VenueApply;
import com.woniuxy.venuemodel.dto.VenueApplyDto;
import com.woniuxy.venuemodel.form.AuthVenueApplyForm;
import com.woniuxy.venuemodel.form.FindVenueApplyForm;
import com.woniuxy.venuemodel.form.RefuseVenueApplyForm;
import com.woniuxy.venuemodel.param.AuthVenueApplyParam;
import com.woniuxy.venuemodel.param.FindVenueApplyParam;
import com.woniuxy.venueservice.exception.VenueException;
import com.woniuxy.venueservice.service.VenueApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 场馆申请入驻表 前端控制器
 * </p>
 *
 * @author 冉杰
 * @since 2024-01-15
 */
@RestController
@RequestMapping("/venueApply")
@Api(tags = "场馆申请信息接口")
public class VenueApplyController {

    @Autowired
    private VenueApplyService venueApplyService;

    @PostMapping("/findVenueApplyByCondition.api")
    @ApiOperation("按条件查看场馆申请记录接口")
    public Result findVenueApplyByCondition(@RequestBody FindVenueApplyForm form){
        FindVenueApplyParam param = BeanUtil.toBean(form, FindVenueApplyParam.class);
        PageInfo<VenueApply> pageInfo = venueApplyService.findVenueApplyByCondition(param);
        return Result.success("成功查询场馆申请记录",pageInfo);
    }

    @PostMapping("/authVenue.api")
    @ApiOperation("同意认证场馆接口")
    public Result authVenue(@RequestBody @Validated AuthVenueApplyForm form,@RequestHeader String token){
        AuthVenueApplyParam param = BeanUtil.toBean(form, AuthVenueApplyParam.class);
        Integer adminId = MyJwtUtil.getAdminIdByKey(token, "adminId");
        param.setAdminId(adminId);
        venueApplyService.authVenue(param);
        return Result.success("成功认证场馆");
    }

    @PostMapping("/refuseVenue.api")
    @ApiOperation("拒绝认证场馆接口")
    public Result refuseVenue(@RequestBody @Validated RefuseVenueApplyForm form,@RequestHeader String token){
        Integer adminId = MyJwtUtil.getAdminIdByKey(token, "adminId");
        venueApplyService.refuseVenue(form,adminId);
        return Result.success("成功拒绝场馆认证");
    }

    @GetMapping("/searchVenueByPhone")
    @ApiOperation("根据手机号查询场馆申请认证接口")
    public Result searchVenueByPhone(String phone){
        List<VenueApplyDto> dtos = venueApplyService.searchVenueByPhone(phone);
        return Result.success("成功查询场馆申请认证信息",dtos);
    }

}

